
// Source File Name:   LIST_ADXPAdapterImpl.java

package com.sunwayhorizo.health.hl7.datatypes.common;

import com.sunwayhorizo.health.hl7.datatypes.ADXP;
import com.sunwayhorizo.health.hl7.datatypes.ANY;
import com.sunwayhorizo.health.hl7.datatypes.BL;
import com.sunwayhorizo.health.hl7.datatypes.CS;
import com.sunwayhorizo.health.hl7.datatypes.INT;
import com.sunwayhorizo.health.hl7.datatypes.LIST_ADXP;
import com.sunwayhorizo.health.hl7.datatypes.TYPE;

import java.util.Iterator;
import java.util.List;


//            LISTAdapterCommonImpl, ADXPImpl, ANYImpl, BLImpl,
//            CSImpl, NullFlavorImpl, TYPEImpl

public class LIST_ADXPAdapterImpl extends LISTAdapterCommonImpl
    implements LIST_ADXP
{
    public static final String RCS_ID = "$Header: LIST_ADXPAdapterImpl.java 1.0 2006/09/16 09:23:22 amchanda noship $";
    private static final LIST_ADXP nullNI = new LIST_ADXPAdapterImpl(CSImpl.valueOf("NI"));
    private static final LIST_ADXP nullOTH = new LIST_ADXPAdapterImpl(CSImpl.valueOf("OTH"));
    private static final LIST_ADXP nullNINF = new LIST_ADXPAdapterImpl(CSImpl.valueOf("NINF"));
    private static final LIST_ADXP nullPINF = new LIST_ADXPAdapterImpl(CSImpl.valueOf("PINF"));
    private static final LIST_ADXP nullUNK = new LIST_ADXPAdapterImpl(CSImpl.valueOf("UNK"));
    private static final LIST_ADXP nullASKU = new LIST_ADXPAdapterImpl(CSImpl.valueOf("ASKU"));
    private static final LIST_ADXP nullNAV = new LIST_ADXPAdapterImpl(CSImpl.valueOf("NAV"));
    private static final LIST_ADXP nullMSK = new LIST_ADXPAdapterImpl(CSImpl.valueOf("MSK"));
    private static final LIST_ADXP nullNA = new LIST_ADXPAdapterImpl(CSImpl.valueOf("NA"));
    private static final LIST_ADXP nullNASK = new LIST_ADXPAdapterImpl(CSImpl.valueOf("NASK"));

    public LIST_ADXPAdapterImpl(CS cs)
    {
        super(cs);
    }

    public LIST_ADXPAdapterImpl(List list)
    {
        super(list);
    }

    public LIST_ADXPAdapterImpl(ADXP aadxp[])
    {
        for(int i = 0; i < aadxp.length; i++)
            mList.add(aadxp[i]);

    }

    public LIST_ADXPAdapterImpl(ADXP adxp)
    {
        mList.add(adxp);
    }

    public ADXP head()
    {
        if(isNull().isTrue())
            return ADXPImpl.nullADXP(NullFlavorImpl.NI);
        ADXP adxp = null;
        try
        {
            adxp = (ADXP)mList.get(0);
        }
        catch(IndexOutOfBoundsException _ex)
        {
            return ADXPImpl.nullADXP(NullFlavorImpl.NI);
        }
        return adxp;
    }

    public LIST_ADXP tail()
    {
        if(isNull().isTrue())
            return nullLIST_ADXP(NullFlavorImpl.NI);
        LIST_ADXPAdapterImpl list_adxpadapterimpl = null;
        try
        {
            List list = mList.subList(1, mList.size());
            list_adxpadapterimpl = new LIST_ADXPAdapterImpl(list);
        }
        catch(IllegalArgumentException _ex)
        {
            return nullLIST_ADXP(NullFlavorImpl.NI);
        }
        return list_adxpadapterimpl;
    }

    public ADXP item(INT int1)
    {
        if(isNull().isTrue())
            return ADXPImpl.nullADXP(NullFlavorImpl.NI);
        ADXP adxp = null;
        try
        {
            adxp = (ADXP)mList.get(int1.intValue());
        }
        catch(IndexOutOfBoundsException _ex)
        {
            return ADXPImpl.nullADXP(NullFlavorImpl.NI);
        }
        return adxp;
    }

    public BL contains(ADXP adxp)
    {
        if(isNull().isTrue())
            return BLImpl.nullBL(NullFlavorImpl.NI);
        else
            return BLImpl.valueOf(mList.contains(adxp));
    }

    public TYPE dataType()
    {
        return com.sunwayhorizo.health.hl7.datatypes.common.TYPEImpl.LIST_ADXP;
    }

    public BL equal(ANY any)
    {
        if(any instanceof LIST_ADXP)
        {
            if(any.isNull().isTrue())
                return BLImpl.FALSE;
            LIST_ADXP list_adxp = (LIST_ADXP)any;
            Iterator iterator = listIterator();
            Iterator iterator1;
            for(iterator1 = list_adxp.listIterator(); iterator.hasNext() && iterator1.hasNext();)
                if(!((ADXP)iterator.next()).equal((ADXP)iterator1.next()).isTrue())
                    return BLImpl.FALSE;

            if(iterator.hasNext() || iterator1.hasNext())
                return BLImpl.FALSE;
            else
                return BLImpl.TRUE;
        } else
        {
            return BLImpl.FALSE;
        }
    }

    public static LIST_ADXP valueOf(List list)
    {
        return new LIST_ADXPAdapterImpl(list);
    }

    public static LIST_ADXP nullLIST_ADXP()
    {
        return new LIST_ADXPAdapterImpl(((CS) (null)));
    }

    public static LIST_ADXP valueOf(ADXP aadxp[])
    {
        return new LIST_ADXPAdapterImpl(aadxp);
    }

    public static LIST_ADXP valueOf(ADXP adxp)
    {
        return new LIST_ADXPAdapterImpl(adxp);
    }

    public Iterator listIterator()
    {
        return mList.listIterator();
    }

    protected boolean verifyItem(Object obj)
    {
        return obj instanceof ADXP;
    }

    public static LIST_ADXP nullLIST_ADXP(CS cs)
    {
        String s = null;
        if(cs == null || cs.literal().stringValue() == null || cs.isNull().isTrue())
            s = "NI";
        else
            s = cs.literal().stringValue();
        if(s.equals("NI"))
            return nullNI;
        if(s.equals("OTH"))
            return nullOTH;
        if(s.equals("NINF"))
            return nullNINF;
        if(s.equals("PINF"))
            return nullPINF;
        if(s.equals("UNK"))
            return nullUNK;
        if(s.equals("ASKU"))
            return nullASKU;
        if(s.equals("NAV"))
            return nullNAV;
        if(s.equals("MSK"))
            return nullMSK;
        if(s.equals("NA"))
            return nullNA;
        if(s.equals("NASK"))
            return nullNASK;
        else
            return nullNI;
    }

}
